<template>
	<view class="mainpadding2">
		<view class="ffffff radius margin_top mainpadding" v-for="item in list.data" :key="item.id">
			<view class="flexbetween xiahuaxian">
				<image class="tupian" :src="item.image_text" mode=""></image>
				<view class="" style="width: 74%;">
					<view class="titletext fonweight zhonghei">{{item.title}}</view>
					<view class="flexleft">
						<view class="strongtext xiaohui  margin_top1">售价</view>
						<view class="xiaohong fonweight sanshier" v-if="item.goods_attr==1">￥{{item.goodsprice.price}}
						</view>
						<view class="xiaohong fonweight sanshier" v-if="item.goods_attr==2">
							￥{{item.goodsprice.pt_price}}</view>
						<view class="xiaohong fonweight sanshier" v-if="item.goods_attr==3">
							￥{{item.goodsprice.ms_price}}</view>
					</view>
					
					<view class="flexbetween">
						<view class="strongtext xiaohui  margin_top1">库存
							<text class="xiaolv fonweight strongtext">{{item.goodsprice.stock}}</text>
						</view>
						<view class="strongtext xiaohui  margin_top1">销量  
							<text class="xiaocheng fonweight strongtext"> {{item.sales}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="flexleft" v-if="item.status=='normal'" @click="xiajia(item.id)">
					<image class="dqicon margin_right1" src="../static/images/system/sj.png" mode=""></image>
					<view class="ershiba zhonghei">下架</view>
				</view>
				<view class="flexleft"  v-if="item.status=='hidden'" @click="shangjia(item.id)">
					<image class="dqicon margin_right1" src="../static/images/system/sj1.png" mode=""></image>
					<view class="ershiba zhonghei">上架</view>
				</view>
				<view class="flexleft" @click="shanchu(item.id)">
					<u-icon name="trash"></u-icon>
					<view class="ershiba zhonghei margin_left1">删除</view>
				</view>
				<view class="flexleft" @click="pingjia(item.id)">
					<image class="dqicon margin_right1" src="../static/images/system/pj.png" mode=""></image>
					<view class="ershiba zhonghei">评价</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				listid:"",
			}
		},
		onLoad(options) {
			this.listid = options.id
		},
		onShow() {
			this.init()
		},
		methods: {
			pingjia(id){
				uni.navigateTo({
					url:"/pages_wode/pingjiagl?shop_id="+this.listid+"&id="+id
				})
			},
			shanchu(id) {
				httpRequest.modal('提示', '是否确认删除当前商品', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/shopcl/delGoods', 'GET', {
							shop_id:this.listid,
							goods_id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			shangjia(id) {
				httpRequest.modal('提示', '是否确认上架当前商品', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/shopcl/clGoodsStatus', 'GET', {
							shop_id:this.listid,
							goods_id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			xiajia(id) {
				httpRequest.modal('提示', '是否确认下架当前商品', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/shopcl/clGoodsStatus', 'GET', {
							shop_id:this.listid,
							goods_id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/shopcl/goodsList', 'GET', {
					page: page || 1,
					limit: _this.limit,
					shop_id: this.listid,
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.dqicon{
	width: 28rpx;
		height: 28rpx;
	}
.tupian{
	width: 140rpx;
	height: 140rpx;
	border-radius: 8rpx 8rpx 8rpx 8rpx;
}
</style>
